﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace Batty
{
    public class Camera
    {
        #region Fields

        private GraphicsDeviceManager graphics;

        /// <summary>
        /// The eye position in space
        /// </summary>
        private Vector3 eye = new Vector3(50, 50, 50);

        /// <summary>
        /// The location we are looking at in space.
        /// </summary>
        private Vector3 center = new Vector3(0, 0, 0);

        /// <summary>
        /// The up direction
        /// </summary>
        private Vector3 up = new Vector3(0, 1, 0);

        private float fov = MathHelper.ToRadians(35);
        private float znear = 10;
        private float zfar = 10000;

        /// <summary>
        /// The computed view matrix
        /// </summary>
        private Matrix view;

        /// <summary>
        /// The computed projection matrix
        /// </summary>
        private Matrix projection;

        #endregion

        #region Properties

        public Matrix View { get { return view; } }
        public Matrix Projection { get { return projection; } }

        #endregion

        #region Construction and Initialization

        /// <summary>
        /// Constructor. Initializes the graphics field from a passed parameter.
        /// </summary>
        /// <param name="graphics">The graphics device manager for our program</param>
        public Camera(GraphicsDeviceManager graphics)
        {
            this.graphics = graphics;
        }

        public void Initialize()
        {
            ComputeView();
            ComputeProjection();
        }

        #endregion

        #region Matrix Computations

        private void ComputeView()
        {
            view = Matrix.CreateLookAt(eye, center, up);
        }

        private void ComputeProjection()
        {
            projection = Matrix.CreatePerspectiveFieldOfView(fov,
                graphics.GraphicsDevice.Viewport.AspectRatio, znear, zfar);
        }

        #endregion

    }
}
